#include<graphics.h>
#include<conio.h>
#include<math.h>

#define High 640
#define Width 810
#define PI 3.14159

int main()
{
	initgraph(Width,High);

	int center_x,center_y;  //中心坐标
	center_x=Width/2;
	center_y=High/2;

	int secondLength;      //秒针的长度
	secondLength=Width/5;

	int minuteLength;      //分针的长度
	minuteLength=Width/6;

	int hourLength;      //时针的长度
	hourLength=Width/7;

	


	int secondEnd_x,secondEnd_y;    //秒针的终点坐标
	secondEnd_x = center_x+secondLength;
	secondEnd_y = center_y;

	int minuteEnd_x,minuteEnd_y;   //分针终点坐标
	minuteEnd_x = center_x+minuteLength;
	minuteEnd_y = center_y;


	int hourEnd_x,hourEnd_y;       //时针终点坐标
	hourEnd_x = center_x+hourLength;
	hourEnd_y = center_y;

	float secondAngle;  //秒针对应转动角度
	float minuteAngle;//分针对应转动角度
	float hourAngle;//时针对应转动角度

	SYSTEMTIME ti;  //定义变量存储系统时间

	BeginBatchDraw();


	while(1)
	{
		//绘制一个简单的表盘
	setlinestyle(PS_SOLID,1);
	setcolor(WHITE);
	circle(center_x,center_y,Width/4);

	//画刻度
	int x,y,i;
	for(i=0;i<60;i++)
	{
		x=center_x+int(Width/4.3*sin(PI*2*i/60));
		y=center_y+int(Width/4.3*cos(PI*2*i/60));
		if(i%15==0)
			bar(x-5,y-5,x+5,y+5);
		else if(i%5==0)
			circle(x,y,3);
		else
			putpixel(x,y,YELLOW);
	}
	outtextxy(center_x-25,center_y+Width/6,"我的时钟");
	outtextxy(center_x-25-15,center_y+Width/6+20,"Made In China");



		GetLocalTime(&ti);
		secondAngle=ti.wSecond*2*PI/60;
		minuteAngle=ti.wMinute*2*PI/60;
		hourAngle=ti.wHour*2*PI/60;

		secondEnd_x = center_x+secondLength*sin(secondAngle);
		secondEnd_y = center_y-secondLength*cos(secondAngle);
		//画秒针
		setlinestyle(PS_SOLID,2);
		setcolor(GREEN);
		line(center_x,center_y,secondEnd_x,secondEnd_y);
		
		minuteEnd_x = center_x+minuteLength*sin(minuteAngle);
		minuteEnd_y = center_y-minuteLength*cos(minuteAngle);
		//画分针
		setlinestyle(PS_SOLID,2);
		setcolor(BLUE);
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);

		hourEnd_x = center_x+hourLength*sin(hourAngle);
		hourEnd_y = center_y-hourLength*cos(hourAngle);
		//画时针
		setlinestyle(PS_SOLID,2);
		setcolor(RED);
		line(center_x,center_y,hourEnd_x,hourEnd_y);


		FlushBatchDraw();

		Sleep(50);
		
		//隐藏之前的秒针
		setcolor(BLACK);
		line(center_x,center_y,secondEnd_x,secondEnd_y);
		setcolor(BLACK);
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);
		setcolor(BLACK);
		line(center_x,center_y,hourEnd_x,hourEnd_y);
		
		

	}

	EndBatchDraw();

	getch();
	closegraph();


	return 0;
}
